package org.offsync.util

trait Disposable {
  def disposeState: DisposeState
  
  def dispose(): Unit
  
  def waitDisposed(
      deadline: Time = Never): Unit
  
  def using[T](f: this.type => T): T = try f(this) finally dispose()
}

object Disposed extends Disposable {
  override def disposeState = DisposeState.Disposed
  
  override def dispose(): Unit = { }
  
  override def waitDisposed(
      deadline: Time): Unit = { }
}
